package com.lgh.springframework.aop.framework;

import com.lgh.springframework.aop.AdvisedSupport;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname ProxyFactory
 * @description
 * @date 2023/03/07 20:43
 * <p>
 * ******************************************************
 */
public class ProxyFactory {

    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getProxy() {
        return createAopProxy().getProxy();
    }

    private AopProxy createAopProxy() {
        if (advisedSupport.isProxyTargetClass()) {
            return new Cglib2AopProxy(advisedSupport);
        }

        return new JdkDynamicAopProxy(advisedSupport);
    }

}
